import { baseApiUrl, path } from "../../utils/config";
import { product } from '../../utils/api';
const app = getApp();
Page({
  data: {
    baseImageUrl: baseApiUrl,

    page: 1,
    last_page: 1,
    list: []
  },
  async onLoad(options) {
    this.getList();
  },
  onReachBottom() {
    let page = this.data.page;
    let last_page = this.data.last_page;
    if (page == last_page) return false;
    page += 1;
    this.setData({ page });
    this.getList();
  },
  async getList() {
    let res = await product({
      page: this.data.page,
      limit: 10
    });
    res = res.product;
    let { data, last_page } = res;
    let list = this.data.page == 1 ? data : [...this.data.list, ...data];
    this.setData({ list, last_page })
  },
  router(e) {
    let { url } = e.currentTarget.dataset;
    wx.navigateTo({ url })
  },
  onShareAppMessage() {
    let poster = app.globalData.poster;
    return {
      path,
      imageUrl: poster
    }
  },
  onShareTimeline() { }
})